﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace SpriteSample
{
    class ResourceManager
    {
        //private Sprite m_player_stand;
        List<Sprite> m_spriteList = new List<Sprite>();
        //singleton pointer
        private static ResourceManager m_pInstence = null;
        //ContentManager Content;
        //constructor
        
        private ResourceManager()
        {
            //Content.RootDirectory = "Content";
            //m_player_stand = new Sprite(5, 5, 66, 74);
            m_spriteList.Add(new Sprite("Player/queen_standing",5, 5, 66, 74));
            m_spriteList.Add(new Sprite("Player/queen_walking", 4, 4, 72, 71));
            m_spriteList.Add(new Sprite("Player/queen_jump", 1, 1, 47, 75));

            m_spriteList.Add(new Sprite("Title Object/ground1", 1, 1, 450, 109));
            m_spriteList.Add(new Sprite("Title Object/Brick", 1, 1, 50, 50));
        }

        public void LoadContent(ContentManager _contentManager)
        {
            int _lastFrame;
            int _interval = 150;
            for (int i = 0; i < m_spriteList.Count(); i++)
            {
                _lastFrame = m_spriteList[i].TotalFrame - 1;
                m_spriteList[i].LoadContent(_contentManager, 0, _lastFrame, _interval);
            }
        }

        public static ResourceManager GetInstance()
        {
            if (m_pInstence == null)
            {
                m_pInstence = new ResourceManager();
                return m_pInstence;
            }
            else
                return m_pInstence;
        }

        public Sprite GetSprite(String _spriteName)
        {
            for (int i = 0; i < m_spriteList.Count(); i++)
            {
                //int t = String.Compare(m_spriteList[i].SpriteName, _spriteName);
                //t *= 1;
                
                if (String.Compare(m_spriteList[i].SpriteName.ToString(), _spriteName.ToString()) == 0)
                {
                    return m_spriteList[i];
                    //result = m_spriteList.ElementAt(i);
                }
            }
            return null;
        }

    }
}
